<style type="text/css">
    .selected-search {
        border: 1px solid #dddee1;
        height: 200px;
        width: 260px;
        position: relative;
        border-radius: 4px;
    }

    .selected-search .search-action {
        position: absolute;
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .selected-search .selected-arr {
        position: absolute;
        top: 50px;
        left: 20px;
        right: 20px;
        bottom: 10px;
        overflow: scroll;
    }

    .select-click {
        border: 1px solid #dddee1;
        border-radius: 4px;
        padding: 0 10px;
        margin-bottom: 10px;
    }

    .selected-search .selected-arr .selected-item {
        /*border-bottom: 1px solid #dfdfdf;*/
    }
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="110">
        <Form-item label="报修人：">
            <Radio-group v-model="formValidate.isSlef">
                <Radio label="1">自己</Radio>
                <Radio label="2">他人</Radio>
            </Radio-group>
        </Form-item>
        <template v-if="formValidate.isSlef ==2">
            <Form-item label="联系人" prop="people">
                <i-input v-model="formValidate.people" placeholder="请输入联系人"></i-input>
            </Form-item>
            <Form-item label="联系人电话" prop="contact">
                <i-input v-model="formValidate.contact" placeholder="请输入联系人电话"></i-input>
            </Form-item>
        </template>
        <Form-item label="保修详情" prop="requestcontent">
            <Input v-model="formValidate.requestcontent" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="请输入..."></Input>
        </Form-item>
        <!--<Form-item label="状态" prop="state">-->
            <!--<i-select v-model="formValidate.state" placeholder="请选择状态">-->
                <!--<i-option value="申请">申请</i-option>-->
                <!--<i-option value="处理中">处理中</i-option>-->
                <!--<i-option value="派工">派工</i-option>-->
                <!--<i-option value="完成">完成</i-option>-->
                <!--<i-option value="用户撤销">用户撤销</i-option>-->
                <!--<i-option value="管理员撤销">管理员撤销</i-option>-->
            <!--</i-select>-->
        <!--</Form-item>-->
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost" style="margin-left: 8px">取消</i-button>
        </Form-item>
    </i-form>

</template>
<script>
    import apiUtil from '../../assets/utils/api_util';

    export default {
        data() {
            return {
                formValidate: {
                    //添加字段
                    people: '',
                    contact: '',
                    isSlef:"1",  //1_自己 ,2_他人
                    requestcontent:'',
                },
                ruleValidate: {
                    people: [
                        {required: true, message: '联系人不能为空', trigger: 'blur'}
                    ],
                    contact: [
                        {required: true, message: '联系人电话不能为空', trigger: 'blur'}
                    ],
                    requestcontent: [
                        {required: true, message: '请填写保修详情', trigger: 'blur'}
                    ],
                },
                editType:'',
            }
        },
        mounted: function () {
            let id = this.$route.query.id;
            this.editType = this.$route.query.type;

            if (id && id.length > 0) {

                this.getDetail(id)
            }

        },

        methods: {
            changeStartDate: function (date) {
                console.log(date)
                this.formValidate.expiredatestart = date;
            },
            changeEndDate: function (date) {
                console.log(date);
                this.formValidate.expiredateend = date;

            },
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.updateData(model);
                })
            },
            //详情
            getDetail: function (id) {
                let that = this;
                that.$Loading.start();

                let para = {
                    curPage: this.$route.query.curPage,
                    pageSize: 10,
                    opid: '87415a1b-922e-4a94-83c6-8f16c74ab0fb',
                };

                apiUtil.get(that, apiUtil.urls.ListRepireLog, para, function (res) {
                    let data = res.Msg.Arrays[that.$route.query.index];

                    if(data.people){
                        that.formValidate.isSlef = "2";
                        that.formValidate.people = data.people;
                        that.formValidate.contact = data.contact;

                    }
                    if(data.ForPeopleName){
                        that.formValidate.isSlef = "1";
                    }

                    that.formValidate.requestcontent =data.requestcontent;

                    console.log('data:',data)
                    // that.formValidate.sextype = data.sextype;
                    // that.formValidate.dormtype = data.dormtype;
                    // that.formValidate.peoplecount = data.peoplecount.toString();
                    // that.formValidate.location = data.location;
                    // that.formValidate.dormcode = data.dormcode;
                    // that.formValidate.comment = data.comment;
                });
            },
            //修改
            updateData: function (model) {
                let that = this;
                let postData ={};

                postData.id =that.$route.query.id;
                if(model.isSlef ==1 ){
                    postData.forpeopleid = '52a1ecea-e787-4b9d-b3b0-74672dc775d6';
                    postData.requestcontent = model.requestcontent;
                }else {
                    postData.requestcontent = model.requestcontent;
                    postData.contact = model.contact;
                    postData.people = model.people;
                }

                let params = that.$qs.stringify(postData);

                this.$Loading.start();

                apiUtil.post(that,apiUtil.urls.EditRepairForm, params, function (res) {
                    that.$Loading.finish();
                    that.$message.success('编辑成功')
                });
            },


        }
    }
</script>
